<?php
// No direct access
defined('_JEXEC') or die;

jimport('joomla.application.component.view');

class JeneratorViewArticles extends JView
{
	protected $items;
	protected $pagination;
	protected $state;

	/**
	 * Display the view
	 */
	public function display($tpl = null)
	{
		$this->state = $this->get('State');
		$this->items = $this->get('Items');
		$this->pagination = $this->get('Pagination');

		// Check for errors.
		if (count($errors = $this->get('Errors'))) {
			JError::raiseError(500, implode("\n", $errors));
			return false;
		}

		$this->addToolbar();
		parent::display($tpl);
	}

	/**
	 * Add the page title and toolbar.
	 *
	 * @since	1.6
	 */
	protected function addToolbar()
	{
		JLoader::register('JeneratorHelper', JPATH_COMPONENT.'/helpers/jenerator.php');

		$state	= $this->get('State');
		$canDo	= JeneratorHelper::getActions($state->get('filter.category_id'));
		$user	= JFactory::getUser();

		JToolBarHelper::title(JText::_('COM_JENERATOR_MANAGER_ARTICLES'), 'newsfeeds.png');

		// Add export toolbar
		$bar = JToolBar::getInstance('toolbar');
		$bar->appendButton('Popup', 'export', 'COM_JENERATOR_TOOLBAR_UPDATE', 'index.php?option=com_jenerator&task=articles.update');

		if ($canDo->get('core.admin')) {
			JToolBarHelper::preferences('com_jenerator');
			JToolBarHelper::divider();
		}

		JToolBarHelper::help('', '', JText::_('COM_JENERATOR_ARTICLES_HELP_LINK'));
	}
}
